<?php $this->load->view('common/head');?>

<?php $this->load->view('common/header');?>
<div class="main-container" id="main-container">
    <script type="text/javascript">
        try {
            ace.settings.check('main-container', 'fixed')
        } catch (e) {
        }
    </script>

    <?php $this->load->view('common/sidebar');?>
    <div class="main-content">
        <div class="main-content-inner">
            <!-- #section:basics/content.breadcrumbs -->
            <?php $this->load->view('common/breadcrumbs');?>

            <!-- /section:basics/content.breadcrumbs -->
            <div class="page-content">

                <?php $this->load->view('common/set');?>

                <!-- /section:settings.box -->
                <div class="row">
                    <form class="form-inline" action="<?php echo site_url(X_URL.'area/index')?>" method="get" id="form2">
                        <?php echo csrf_hidden();?>
                        <label class="inline">地区标题:<input type="text" name="area_title" id="area_title"/></label>
                        <button type="submit" class="btn btn-purple btn-sm" id="submit">
                            <span class="ace-icon fa fa-search icon-on-right bigger-110"></span>
                            查询
                        </button>
                        <span class="btn btn-purple btn-sm" id="addarea">
                            <span class="ace-icon fa fa-user icon-on-right bigger-110"></span>
                            新增地区
                        </span>
                    </form>

                    <div class="col-xs-12">
                        </div>
                        <table class="table table-striped table-bordered">
                            <thead>
                                <tr>
                                    <th width="20%" class="center">地区ID</th>
                                    <th class="center">地区名称</th>
                                    <th class="center">操作</th>
                                </tr>
                            </thead>
                            <tbody>

                            <?php if($areas){ foreach ($areas as $key => $val) { ?>
                                <tr>
                                    <td  class="center"><?php echo $val['area_id']; ?></td>
                                    <td><?php echo $val['area_name']; ?></td>
                                    <td class="center">
                                        <a href="<?php echo site_url(X_URL.'area/edit/'.$val['area_id']);?>"><i
                                                    class="ace-icon fa fa-pencil bigger-100 red"></i>修改</a>&nbsp;
                                        <?php if(empty($val['parent_id'])) { ?>
                                            <a href="javascript:;" val="<?php echo site_url(X_URL.'area/add_son');?>" pid="<?php echo $val['area_id']?>" class="add"><i
                                                        class="ace-icon fa fa-pencil bigger-100 red"></i>增加子类</a>&nbsp;&nbsp;
                                        <?php }?>
                                    </td>
                                </tr>
                            <?php } ?>
                            <?php }?>
                            </tbody>
                        </table>
                        <?php if($pagination){?><ul class="pagination"><?php echo $pagination;?></ul><?php }?>
<!--                        {$page}-->
                        <!-- PAGE CONTENT ENDS -->
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div><!-- /.page-content -->
    </div><!-- /.main-content -->
    <?php $this->load->view('common/footer');?>
</div>


<?php $this->load->view('common/footerjs');?>
<!-- inline scripts related to this page -->
<script type="text/javascript">

    $(function () {
        $("#officialnews ul").html('<div class="ace-icon fa fa-spinner fa-spin orange"></div>');
    })
    $("#addarea").click(function () {
        window.location.href="add";
    });
    $("#submit").click(function () {
        var title = $("#title").val();
        if (title == '') {
                bootbox.dialog({
                    title: "系统提示",
                    message: "搜索标题必须填写！",
                    buttons: {
                        "success": {
                            "label": "确定",
                            "className": "btn-danger"
                        }
                    }
                });
                return false;
            }
        $("#form2").submit();
    });
    //prompt层
    $(".add").click(function () {
        var pid = $(this).attr("pid");
        var url = $(this).attr("val");
        layer.prompt({title: '请填写该地区下级名称'}, function(value, index){
            $.ajax({
                type : "post",
                url: url,
                data: {'parent_id':pid,'area_name':value,'csrf_test_name': ci_csrf_token()},
                dataType:"JSON",
                success: function (msg) {
                    if(msg.status==1){
                        layer.msg(msg.info, {
                            time: 1000, //1s后自动关闭
                            shade: 0.1
                        }, function () {
                            window.location.href = window.location.href;
                        });
                    }else{
                        layer.msg(msg.msg);
                        return false;
                    }
                }
            })
        });
    });
</script>
</body>
</html>
